package com.sky.controller.admin;

import com.sky.dto.OrdersCancelDTO;
import com.sky.dto.OrdersConfirmDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.dto.OrdersRejectionDTO;
import com.sky.pojo.Courier;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.admin.OrderService;
import com.sky.vo.OrderStatisticsVO;
import com.sky.vo.OrderVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/admin/order")
@Api(tags = "管理端查看订单接口")
public class OrderController {

    @Autowired
    private OrderService orderService;

    @GetMapping("/conditionSearch")
    @ApiOperation(value = "订单搜索")
    public Result<PageResult> findByPage(OrdersPageQueryDTO pageQueryDTO){
        PageResult result = orderService.findByPage(pageQueryDTO);
        return Result.success(result);
    }

    @GetMapping("/statistics")
    @ApiOperation(value = "订单数量统计")
    public Result<OrderStatisticsVO> countStatus(){
        OrderStatisticsVO orderStatisticsVO = orderService.countStatus();
        return Result.success(orderStatisticsVO);
    }

    @GetMapping("/details/{orderId}")
    @ApiOperation(value = "查询订单")
    public Result<OrderVO> details(@PathVariable Long orderId){
        OrderVO orderVO = orderService.details(orderId);
        return Result.success(orderVO);
    }

    @PutMapping("/cancel")
    @ApiOperation(value = "取消订单")
    public Result<String> cancelOrder(@RequestBody OrdersCancelDTO dto){
        orderService.cancelOrder(dto);
        return Result.success();
    }

    @PutMapping("/rejection")
    @ApiOperation(value = "拒单")
    public Result<String> rejection(@RequestBody OrdersRejectionDTO dto){
        orderService.rejection(dto);
        return Result.success();
    }
    @PutMapping("/confirm")
    @ApiOperation(value = "商家接单")
    public Result<Courier> confirm(@RequestBody OrdersConfirmDTO dto){
        Courier courier = orderService.confirm(dto);
        return Result.success(courier);
    }
}
